import { ExtIdTuple } from "~/db.pg";

import { User } from "@/stream-user/schema.user";
import { Access } from "@/stream-access/schema.access";
import { TonOrderGroup } from "@/river-ton/schema.order";
import { VoucherGroup } from "@/river-voucher/schema.voucher";
import { Gateway, getGateway } from "@/droplet-bus/core.define";
import { OceanGateway } from "./core.define";

type GrantDto<T extends ExtIdTuple> = { refVisitorId: User["uuid32"]; groupId: T["id"] };

export const GateGrantGateway: Gateway = getGateway(OceanGateway, "ocean_gate_grant");
export type doRiverVoucherGroupGrantDto = GrantDto<VoucherGroup>;
export type doRiverTonOrderGroupGrantDto = GrantDto<TonOrderGroup>;
export type doRiverStockeGrantDto = { refVisitorId: User["uuid32"] };

export interface GateGrantInterfaceWithPrimary<T> {
  /** 授权财务记录分组 */
  doVoucherGroupGrant(dto: T & doRiverVoucherGroupGrantDto): Promise<Access>;
  /** 授权订单分组 */
  doTonOrderGroupGrant(dto: T & doRiverTonOrderGroupGrantDto): Promise<Access>;
  /** 授权库存节点（授权路径末尾，需要补充 type 分别对应常规库存/冷卷库存）*/
  doStockeGrant(dto: T & doRiverStockeGrantDto): Promise<Access>;
}
